<template>
  <div>
    <el-table border
              stripe
              :data="emps">
      <el-table-column type="selection" align="left" width="55"></el-table-column>
      <el-table-column prop="name" label="姓名" fixed align="left" width="70"></el-table-column>
      <el-table-column prop="workId" label="龚昊" align="left" width="120"></el-table-column>
      <el-table-column prop="email" label="邮箱地址" align="left" width="200"></el-table-column>
      <el-table-column prop="phone" label="电话号码" align="left" width="120"></el-table-column>
      <el-table-column prop="department.name" label="部门名称" align="left" width="120"></el-table-column>
      <el-table-column  label="工资账套" align="center">
        <template slot-scope="scope">
          <el-tooltip placement="right" v-if="scope.row.salary">
            <div slot="content">
              <table>
                <tr>
                  <td>基本工资</td>
                  <td>{{ scope.row.salary.basicSalary }}</td>
                </tr>
                <tr>
                  <td>交通补助</td>
                  <td>{{ scope.row.salary.trafficSalary }}</td>
                </tr>
                <tr>
                  <td>午餐补助</td>
                  <td>{{ scope.row.salary.lunchSalary }}</td>
                </tr>
                <tr>
                  <td>奖金</td>
                  <td>{{ scope.row.salary.bonus }}</td>
                </tr>
                <tr>
                  <td>养老金比率</td>
                  <td>{{ scope.row.salary.pensionPer }}</td>
                </tr>
                <tr>
                  <td>养老金基数</td>
                  <td>{{ scope.row.salary.pensionBase }}</td>
                </tr>
                <tr>
                  <td>医疗保险比率</td>
                  <td>{{ scope.row.salary.medicalPer }}</td>
                </tr>
                <tr>
                  <td>医疗保险基数</td>
                  <td>{{ scope.row.salary.medicalBase }}</td>
                </tr>
                <tr>
                  <td>公积金比率</td>
                  <td>{{ scope.row.salary.accumulationFundPer }}</td>
                </tr>
                <tr>
                  <td>公积金基数</td>
                  <td>{{ scope.row.salary.accumulationFundBase }}</td>
                </tr>
              </table>
            </div>
            <el-tag>{{ scope.row.salary.name }}</el-tag>
          </el-tooltip>
          <el-tag v-else>暂未设置</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-popover
              placement="left"
              title="编辑工资账套"
              @show="showPop(scope.row.salary)"
              @hide="hidePop(scope.row)"
              :width="200"
              trigger="click">
            <div>
              <el-select v-model="currentSalary" clearable placeholder="请选择">
                <el-option
                    v-for="item in allSalaries"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                </el-option>
              </el-select>
            </div>
            <el-button slot="reference" type="warning">修改工资账套</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-pagination
          background
          @current-change="currentChange"
          @size-change="sizeChange"
          layout="prev, pager, next, jumper, ->, total"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "SalSobCfg",
  data() {
    return {
      emps: [],
      allSalaries: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      currentSalary: 0,
    }
  },
  mounted() {
    this.initSalarySob();
    this.initSalaryies();
  },
  methods: {
    hidePop(data) {
      if (data && this.currentSalary != data.salary.id) {
        let url = '/salary/sobcfg/?eId=' + data.id +'&salaryId=' + this.currentSalary;
            this.putRequest(url).then(resp => {
              if (resp) {
                this.initSalarySob();
                this.initSalaryies();
              }
            });
      }
    },
    showPop(salary) {
      if (salary) {
        this.currentSalary = salary.id;
      } else {
        this.currentSalary = null;
      }
    },
    currentChange(page) {
      this.currentPage = page;
      this.initSalarySob();
    },
    sizeChange(size) {
      this.pageSize = size;
      this.initSalarySob();
    },
    initSalarySob() {
      let url = '/salary/sobcfg/?currentPage=' + this.currentPage + '&pageSize=' + this.pageSize;
      this.getRequest(url).then(resp => {
        if (resp) {
          this.emps = resp.obj.data;
          this.total = resp.obj.total;
        }
      });
    },
    initSalaryies() {
      this.getRequest('/salary/sobcfg/salaries').then(resp => {
        if (resp) {
          this.allSalaries = resp.obj;
        }
      });
    }
  }
}
</script>

<style scoped>

</style>